package com.wj.algorithm.lintcode;

import java.util.ArrayList;
import java.util.List;

public class P415 {
    public boolean isPalindrome(String s) {
        if(s == null) {
            return true;
        }
        s = s.replaceAll("[^\\d|a-zA-Z]+", "").toLowerCase();
        if(s.length() <= 1) {
            return true;
        }

        int len = s.length();
        for(int i = 0, last = len - 1; i < len; i ++, last --) {
            if(s.charAt(i) != s.charAt(last)) {
                return false;
            }
        }
        return true;
    }
    
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("A man, a plan, a canal: Panama");
        list.add("race a car");
        P415 p = new P415();
        for(String s : list) {
            System.out.println(s + " : " + p.isPalindrome(s));
        }
    }
}
